<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<script type="text/javascript">
    /**
     * 新增粉丝
     */
    <shiro:hasPermission name="back_gotoFansGroupPage_addFans">
    function addFans(){
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            $("#a_fansGroupId").val(selectedRow[0].fansGroupId);
            $("#a_count").val(selectedRow[0].count);
            $("#btn_addFans").attr("data-target", "#addFansModal");/**选中了记录后才可打开对应的模态框**/
            /** 重置当前未选中的列表中的查询条件**/
            $("#qform_sub")[0].reset();
            /** 刷新当前未选中的列表**/
            $("#tt_fansUserInfo").bootstrapTable('refresh');
        } else {
            $("#btn_addFans").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
    </shiro:hasPermission>

    /**
     * 粉丝列表
     */
    $(function(){
        var $tt_fansUserInfo = $("#tt_fansUserInfo").bootstrapTable({
            url: '${basePath}/back/wx/fansGroup/UnGroupedFansList.sjson?',         	/**请求后台的URL（*）**/
            method: 'post',                       	/**请求方式（*）**/
            contentType: "application/x-www-form-urlencoded",
            dataType: 'json',
            toolbar: '#toolbar2',               	 /**工具按钮用哪个容器**/
            striped: false,                      	/**是否显示行间隔色**/
            cache: false,                       	/**是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）**/
            pagination: true,                   	/**是否显示分页（*）**/
            sortable: false,                    	/**是否启用排序**/
            sortOrder: 'asc',                   	/**排序方式**/
            queryParamsType: '',
            sidePagination: 'server',           	/**分页方式：client客户端分页，server服务端分页（*）**/
            pageNumber: 1,
            pageSize:10,							/**初始化加载第一页，默认第一页**/
            pageList: [5,10, 25, 50],        	    /**可供选择的每页的行数（*）**/
            search: false,                       	/**是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大**/
            strictSearch: true,
            showColumns: false,                  	/**是否显示所有的列**/
            showRefresh: false,                  	/**是否显示刷新按钮**/
            minimumCountColumns: 2,             	/**最少允许的列数**/
            clickToSelect: true,                	/**是否启用点击选中行**/
            uniqueId: 'userId',                     /**每一行的唯一标识，一般为主键列**/
            singleSelect:true,                     /** 单选checkbox**/
            showToggle:false,                    	/**是否显示详细视图和列表视图的切换按钮**/
            cardView: false,                    	/**是否显示详细视图**/
            detailView: false,                  	/**是否显示父子表**/
            columns: [
                {checkbox: true},
                {field: 'Number', title: '编号', align: 'center', valign: 'middle', width: '50px',
                    formatter: function (value, row, index) {
                        var page = $tt_fansUserInfo.bootstrapTable("getPage");
                        return page.pageSize * (page.pageNumber - 1) + index + 1;
                    }
                },
                {field: 'nickName', title: '昵称', align: 'center', valign: 'middle'},
                {field:"plateFormRemark",title:"名称备注",align: 'center',valign: 'middle',
                    formatter:function (value,row,index) {
                        if(value==""||value==undefined){
                            return "";
                        }else{
                            return value;
                        }
                    }
                },
                {field:"sex",title:"性别",align: 'center',valign: 'middle',
                    formatter:function (value,row,index) {
                        if(value=="2"){
                            return "女";
                        }else if(value=="1"){
                            return "男";
                        }else{
                            return "";
                        }
                    }
                },
                {field:"customerAddress",title:"会员地址",align: 'center',valign: 'middle',
                    formatter:function (value,row,index) {
                        var customerAddress="";
                        if (row.userCountry!=""&&row.userCountry!=undefined){
                            customerAddress+=row.userCountry;
                            if (row.userProvince!=""&&row.userProvince!=undefined){
                                customerAddress+="-"+row.userProvince;
                                if (row.userCity!=""&&row.userCity!=undefined){
                                    customerAddress+="-"+row.userCity;
                                    return customerAddress;
                                }
                                return customerAddress;
                            }
                            return customerAddress;
                        } else{
                            return customerAddress;
                        }
                    }
                },
                {field:"subscribeTime",title:"关注时间",align: 'center',valign: 'middle',
                    formatter:function (value,row,index) {
                        if(value!=""&&value!=undefined){
                            return toJsonDate(value,"yyyy-MM-dd hh:mm:ss");
                        }else {
                            return "";
                        }
                    }
                }
            ],
            queryParams: function (params) {
                /**特别说明，返回的参数的值为空，则当前参数不会发送到服务器端,这种指定请求参数的方式和datatables控价类似**/
                params.nickName = $("#q_sub_nickName").val();
                params.subscribeBeginTime = $("#q_sub_subscribeBeginTime").val();
                params.subscribeEndTime = $("#q_sub_subscribeEndTime").val();
                params.currentPage = params.pageNumber;
                return params;
            }
        });

        /**表单查询**/
        $("#btn_query_sub").click(function () {
            $("#tt_fansUserInfo").bootstrapTable('refresh');
        });
    });

    /** 表单异步提交**/
    function saveFansUserInfo() {
        /**获取选中行的id**/
        var selectedRow= $("#tt_fansUserInfo").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            var id = selectedRow[0].userId;
            $("#userId").val(id);
            var options = {
                url: $("#form_select").attr("action"),
                type : "post",
                dataType:"json",
                success : function(data) {
                    if(data.success==true){
                        /** 先重置查询框的值**/
                        resetQueryForm();
                        /** 重新刷新列表数据**/
                        $("#tt").bootstrapTable('refresh');
                        /** 自动关闭弹出模态框窗口**/
                        $(".close").click();
                        showMsg("保存成功！");
                    }else{
                        showMsg("保存失败！");
                    }
                }
            };
        $("#form_select").ajaxSubmit(options);
        } else {
            showMsg("请选择一行记录！");
        }
    }
</script>
<!--新增粉丝模态框（Modal） -->
<div class="modal fade" id="addFansModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width:80%">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h5 class="modal-title" id="myModalLabel">未分组粉丝用户</h5>
            </div>

            <div class="modal-body" style="padding-top: 5px;">
                <!-- 查询条件 -->
                <div class="panel panel-default" style="margin-top: 15px;">
                    <div class="panel-body">
                        <form id="qform_sub" class="form-horizontal">
                            <div class="form-group" style="margin-top:15px">
                                <div class="col-sm-2" style="width:250px;">
                                    <div class="input-group input-group-sm">
                                        <span class="input-group-addon">昵称</span>
                                        <input type="text" class="form-control" id="q_sub_nickName" name="nickName" placeholder="请输入昵称"/>
                                    </div>
                                </div>
                                <div class="col-sm-4" style="width: 340px;">
                                    <div class="input-group input-group-sm ">
                                        <span class="input-group-addon">关注开始时间</span>
                                        <div class="input-group date form_datetime" data-link-field="dtp_input1">
                                            <input id="q_sub_subscribeBeginTime" name="subscribeBeginTime" style="height: 30px; border: 1px solid #c6c6c6;border-right:none;padding-left:10px; " size="20" type="text" value=""  placeholder="请选择关注开始时间" readonly>
                                            <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                            <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                                        </div>
                                        <script type="text/javascript">
                                            $('.form_datetime').datetimepicker({format: "yyyy-MM-dd",language:'zh-CN',weekStart:1, todayBtn:1,autoclose: 1,todayHighlight: 1,startView: 2, minView: 2, forceParse: 0});
                                        </script>
                                    </div>
                                </div>
                                <div class="col-sm-4" style="width: 340px;">
                                    <div class="input-group input-group-sm ">
                                        <span class="input-group-addon">关注结束时间</span>
                                        <div class="input-group date form_datetime" data-link-field="dtp_input1">
                                            <input id="q_sub_subscribeEndTime" name="subscribeEndTime" style="height: 30px; border: 1px solid #c6c6c6;border-right:none;padding-left:10px; " size="20" type="text" value=""  placeholder="请选择关注结束时间" readonly>
                                            <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                            <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                                        </div>
                                        <script type="text/javascript">
                                            $('.form_datetime').datetimepicker({format: "yyyy-MM-dd",language:'zh-CN',weekStart:1, todayBtn:1,autoclose: 1,todayHighlight: 1,startView: 2, minView: 2, forceParse: 0});
                                        </script>
                                    </div>
                                </div>
                                <div class="col-sm-2" style="width:160px;">
                                    <button type="button" id="btn_query_sub" class="btn btn-primary">查询</button>&nbsp;&nbsp;
                                    <button type="reset" class="btn btn-success" id="resetBtn" >重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

                <form id="form_select"  method="post" action="/back/wx/fansGroup/addFansUserInfo.sjson">
                    <input id="userId" type="hidden" name="userId" noclear="true"/>
                    <input id="a_fansGroupId" type="hidden" name="fansGroupId" noclear="true"/>
                    <input id="a_count" type="hidden" name="count" noclear="true"/>
                    <!-- 渲染的table -->
                    <table id="tt_fansUserInfo"></table>
                </form>
            </div>

            <div class="modal-footer">
                <button type="button" id="validateBtn2" class="btn btn-primary"  onclick="saveFansUserInfo()">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
